InĀ [17]:
import xml.etree.ElementTree as ET
import pandas as pd



import numpy as np
import matplotlib.pyplot as plt
from matplotlib.path import Path
from matplotlib.patches import PathPatch
from matplotlib import cm
from matplotlib import colormaps as cm

import math 
import statistics

from ROOT import TCanvas, TH1F, TGraph, gROOT
from array import array


import pprint
import re

Input padplane mapping¶

InĀ [2]:
new_maps = [ 
    'PadPlane/AutoPad-R1-RevA.sch',
    'PadPlane/AutoPad-R2-RevA-Pads.sch',
    'PadPlane/AutoPad-R3-RevA.sch',
]
old_maps = [ 
    'AutoPad-R1-RevA.sch',
    'AutoPad-R2-RevA-Pads.sch',
    'AutoPad-R3-RevA.sch',
]
InĀ [4]:
# Parameters
num_circles = 4  # Number of concentric circles
num_sectors = 12  # Number of radial divisions (sectors)
inner_radius = 1  # Radius of the inner circle (to exclude the center)
rotation_offset = np.pi / num_sectors  # Half the angle of one sector
module_radius = [31.105,40.249,41.153,57.475,58.367,75.911]
colors = ['tomato','c','green']
InĀ [5]:
new_df_centroids, old_df_centroids = [], []
for imap in new_maps:
    new_df_centroids.append(pd.read_csv(f"{imap}.ChannelMapping.csv"))
for imap in old_maps:
    old_df_centroids.append(pd.read_csv(f"{imap}.ChannelMapping.csv"))
InĀ [6]:
def draw_wagonwheel(view):

    # Create the figure and axis
    fig = plt.figure(figsize=(60, 30))  # Adjust figure size (10x5 is a more typical size)
    # Add polar subplots
    ax1 = fig.add_subplot(121, polar=True)  # 1 row, 2 columns, 1st subplot
    ax2 = fig.add_subplot(122, polar=True) 
    #(ax1,ax2) = plt.subplot(111, polar=True)

    # Draw concentric circles
    circle_radii = np.linspace(inner_radius, inner_radius + num_circles - 1, num_circles)
    for radius in module_radius:
        ax1.plot(np.linspace(0, 2 * np.pi, 100), [radius] * 100, color='black')
        ax2.plot(np.linspace(0, 2 * np.pi, 100), [radius] * 100, color='black')

    # Draw radial lines with rotation offset
    angles = np.linspace(0, 2 * np.pi, num_sectors, endpoint=False) + rotation_offset
    for angle in angles:
        ax1.plot([angle, angle], [module_radius[0], module_radius[5]], color='black')
        ax2.plot([angle, angle], [module_radius[0], module_radius[5]], color='black')
    for side in range(0,2):
        #Drawing Pads
        for sector in range(0, 12):
            phi_text = max(new_df_centroids[1]['PadPhi']) - (max(new_df_centroids[1]['PadPhi']) - min(new_df_centroids[1]['PadPhi']))/2 - np.pi/2
            r_text = new_df_centroids[1]['PadR'][8]/10
            for i in range(0, 3):
                angle_max = (max(new_df_centroids[i]['PadPhi']) - np.pi/2)
                sector_size = max(new_df_centroids[i]['PadPhi'])- min(new_df_centroids[i]['PadPhi'])
                if(side==1):
                    phi_shift = np.pi  - (sector + 1) * np.pi/6
                elif(view=='from outside'):
                    phi_shift = (sector + 1) * np.pi/6
                else:
                    phi_shift = np.pi  - (sector + 1) * np.pi/6
                if (view=='sPHENIX coordinate system' and side ==0):    
                    ax1.plot(-(new_df_centroids[i]['PadPhi'] - np.pi/2) + phi_shift, new_df_centroids[i]['PadR']/10, 'o', markersize=1, color = colors[side])
                    ax1.text(-phi_text + phi_shift, r_text, f"{sector}", color="blue", fontsize=34, ha='center')
                    ax1.plot([-angle_max + phi_shift, -angle_max + phi_shift], [module_radius[2 * i], module_radius[2 * i +1]], color = colors[2])
                    ax1.plot([-(angle_max - sector_size) + phi_shift, -(angle_max - sector_size) + phi_shift], [module_radius[2 * i], module_radius[2 * i +1]],color = colors[2])
                else:
                    if(side==0):
                        ax1.plot((new_df_centroids[i]['PadPhi'] - np.pi/2) + phi_shift, new_df_centroids[i]['PadR']/10, 'o', markersize=1, color = colors[side])
                        ax1.text(phi_text + phi_shift, r_text, f"{sector}", color="blue", fontsize=34, ha='center')
                        ax1.plot([angle_max + phi_shift, angle_max + phi_shift], [module_radius[2 * i], module_radius[2 * i +1]], color = colors[2])
                        ax1.plot([(angle_max - sector_size) + phi_shift, (angle_max - sector_size) + phi_shift], [module_radius[2 * i], module_radius[2 * i +1]], color = colors[2])                
                    else:
                        ax2.plot((new_df_centroids[i]['PadPhi'] - np.pi/2) + phi_shift, new_df_centroids[i]['PadR']/10, 'o', markersize=1, color = colors[side])
                        ax2.text(phi_text + phi_shift, r_text, f"{sector}", color="blue", fontsize=34, ha='center')
                        ax2.plot([angle_max + phi_shift, angle_max + phi_shift], [module_radius[2 * i], module_radius[2 * i +1]], color = colors[2])
                        ax2.plot([(angle_max - sector_size) + phi_shift, (angle_max - sector_size) + phi_shift], [module_radius[2 * i], module_radius[2 * i +1]], color = colors[2])                   

        if(side==0):
            ax1.text(np.pi / 2, 0, f"SOUTH\n{view}", color="red", fontsize=24, ha='center')      
        else:
            ax2.text(np.pi / 2, 0, f"NORTH\n{view}", color="blue", fontsize=24, ha='center')   

        # Formatting
        ax1.set_ylim(0, module_radius[5]+5)
        ax1.axis('off')  # Turn off the axis
        ax2.set_ylim(0, module_radius[5]+5)
        ax2.axis('off')  # Turn off the axis
    # Show the plot
    plt.show()
    if(view=='from outside'):
        fig.savefig("pics/WagonWheel_side_FromOutside.pdf", bbox_inches='tight')
    else:
        fig.savefig("pics/WagonWheel_side_sPHENIX.pdf", bbox_inches='tight')
InĀ [7]:
view={'sPHENIX coordinate system', 'from outside'} #0 - From outside, 1 - sPHENIX coordinate system (z axis is from NORTH to SOUTH)
for v in view:
        draw_wagonwheel(v)
No description has been provided for this image
No description has been provided for this image
InĀ [23]:
Z0 = (new_df_centroids[0]['PadPhi'].to_numpy() - old_df_centroids[0]['PadPhi'].to_numpy() - math.pi/2.)*1.e3*new_df_centroids[0]['PadR']
Z1 = (new_df_centroids[1]['PadPhi'].to_numpy() - old_df_centroids[1]['PadPhi'].to_numpy() - math.pi/2.)*1.e3*new_df_centroids[1]['PadR']
Z2 = (new_df_centroids[2]['PadPhi'].to_numpy() - old_df_centroids[2]['PadPhi'].to_numpy() - math.pi/2.)*1.e3*new_df_centroids[2]['PadR']
print("module 0:", Z0[-5:].tolist(),"\nmodule 1:",Z1[-5:].tolist(),"\nmodule 2:",Z2[-5:].tolist())
module 0: [-16.201151885141677, -15.787614469587728, -16.666137081127935, -15.942775693349091, -386.8875113056071] 
module 1: [15.646001073199107, 15.893312922783636, 16.1433886136999, 15.19421753944455, -260.1929458708448] 
module 2: [9.61969832643763, 9.502615973332698, 9.780030698456494, 9.415433109120631, -83.71991240297223]
InĀ [9]:
from matplotlib import colormaps as cm

X = new_df_centroids[0]['PadX'].to_numpy()
Y = new_df_centroids[0]['PadY'].to_numpy()

# Create figure
fig, ax = plt.subplots(figsize=(30, 30))

# Choose twilight
cmap = cm.get_cmap('Paired')

# Normalize Z values to colormap range
norm = plt.Normalize(vmin=np.nanmin(Z), vmax=np.nanmax(Z))
colors = cmap(norm(Z))

# Scatter plot with colors based on Z values
scatter = ax.scatter(X, Y, c=Z, cmap=cmap)

# Add colorbar
cbar = fig.colorbar(scatter, ax=ax)
cbar.set_label('Z values')

plt.xlabel('X')
plt.ylabel('Y')
plt.title('Scatter plot with Z-value color mapping')
plt.show()
No description has been provided for this image
InĀ [Ā ]:
X = new_df_centroids[0]['PadX'].to_numpy()
Y = new_df_centroids[0]['PadY'].to_numpy()

# Create figure
fig, ax = plt.subplots(figsize=(30, 30))

# Choose twilight
cmap = cm.get_cmap('seismic')

# Normalize Z values to colormap range
norm = plt.Normalize(vmin=np.nanmin(Z), vmax=np.nanmax(Z))
colors = cmap(norm(Z))

# Scatter plot with colors based seismicon Z values
scatter = ax.scatter(X, Y, c=Z, cmap=cmap)

# Add colorbar
cbar = fig.colorbar(scatter, ax=ax)
cbar.set_label('Z values')

plt.xlabel('X')
plt.ylabel('Y')
plt.title('Scatter plot with Z-value color mapping')
plt.show()
No description has been provided for this image
InĀ [15]:
imodule = 1

X = new_df_centroids[imodule]['PadX'].to_numpy()
Y = new_df_centroids[imodule]['PadY'].to_numpy()
Z = (new_df_centroids[imodule]['PadPhi'].to_numpy() - old_df_centroids[imodule]['PadPhi'].to_numpy() - math.pi/2.)*1.e3*new_df_centroids[imodule]['PadR']

# Create figure
fig, ax = plt.subplots(figsize=(30, 30))

# Choose twilight
cmap = cm.get_cmap('coolwarm')

# Normalize Z values to colormap range
norm = plt.Normalize(vmin=np.nanmin(Z), vmax=np.nanmax(Z))
colors = cmap(norm(Z))

# Scatter plot with colors based on Z values
scatter = ax.scatter(X, Y, c=Z, cmap=cmap)

# Add colorbar
cbar = fig.colorbar(scatter, ax=ax)
cbar.set_label('Z values')

plt.xlabel('X')
plt.ylabel('Y')
plt.title('Scatter plot with Z-value color mapping')
plt.show()
No description has been provided for this image
InĀ [16]:
imodule = 2

X = new_df_centroids[imodule]['PadX'].to_numpy()
Y = new_df_centroids[imodule]['PadY'].to_numpy()
Z = (new_df_centroids[imodule]['PadPhi'].to_numpy() - old_df_centroids[imodule]['PadPhi'].to_numpy() - math.pi/2.)*1.e3*new_df_centroids[imodule]['PadR']

# Create figure
fig, ax = plt.subplots(figsize=(30, 30))

# Choose twilight
cmap = cm.get_cmap('coolwarm')

# Normalize Z values to colormap range
norm = plt.Normalize(vmin=np.nanmin(Z), vmax=np.nanmax(Z))
colors = cmap(norm(Z))

# Scatter plot with colors based on Z values
scatter = ax.scatter(X, Y, c=Z, cmap=cmap)

# Add colorbar
cbar = fig.colorbar(scatter, ax=ax)
cbar.set_label('Z values')

plt.xlabel('X')
plt.ylabel('Y')
plt.title('Scatter plot with Z-value color mapping')
plt.show()
No description has been provided for this image
InĀ [11]:
!jupyter nbconvert --to html TestChannelMapping.ipynb --HTMLExporter.theme=dark
[NbConvertApp] Converting notebook TestChannelMapping.ipynb to html
[NbConvertApp] Writing 6157063 bytes to TestChannelMapping.html